<?php
/**
 * Logiciel : exemple d'utilisation de HTML2PDF
 * 
 * Convertisseur HTML => PDF, utilise fpdf de Olivier PLATHEY 
 * Distribué sous la licence GPL. 
 *
 * @author		Laurent MINGUET <webmaster@spipu.net>
 */
session_start();
include '../../connect.php';
require '../../functions.inc';

if ( isset($_GET['pseudo']) )
{
	
	$sql = "SELECT public FROM $table_name 
			WHERE user_name='$_GET[pseudo]'";
	$result = mysql_query($sql,$db);
	$public = mysql_fetch_array($result);
	
	if ( $_SESSION['logname'] == $_GET[pseudo] )
	{
	
	$pseudo = $_GET[pseudo];

	ob_start();
?>
<style type="text/css">
<!--
.container {
	width: 500px;
	margin:auto;
	background-color: #CCC;
}
#main 
{
	width: 600px;
	margin: auto;
}
.mod {
background:#EEEEEE;
border-color:#C7C7C7;
}
.mod {
background:#EEEEEE;
border:1px dotted #C7C7C7;
font-size:1em;
padding:0.2em;
}

-->
</style>

<page style="font-size: 12px">
<?php

	if ( isset($_GET['vuehtml']) )
	{
		echo "<div id=\"main\">";
		    	
	}

?>
	<?php
		$sql = "SELECT * FROM $table_name 
				WHERE user_name='$pseudo'";
		$result = mysql_query($sql,$db);
		$userid = mysql_fetch_array($result);
	?>
	
	<span style="font-weight: bold; font-size: 12pt; color: #CCC"><?php echo $userid['first_name'];?> <?php echo $userid['last_name'];?> Resume<br></span>
	<br />
	<table class="mod" style="font-weight: bold; width:100%;font-size:1.2em"><tr><td style="width:100%;">Contacts</td></tr></table>
	<br/>
	<table>
		<tr>
			<td style="width:9%;vertical-align:top; text-align:right;"></td>
		    <td style='text-align:right;'><b><?php echo $userid['first_name'];?></b></td>
			<td><strong><?php echo $userid['last_name'];?></strong></td>
		</tr>
		<tr>
			<td style="width:9%;vertical-align:top; text-align:right;"></td>
			<td style='text-align:right;'>Adresse:</td>
			<td><?php echo $userid['street'];?>, <?php echo $userid['city'];?></td>
		</tr>
		
		<?php if ( $userid['zip'] != "" && $userid['city'] != "")
			{ ?>
		<tr>
			<td style="width:9%;vertical-align:top; text-align:right;"></td>
			<td style='text-align:right;'>Ville:</td>
			<td><?php echo $userid['zip'];?> <?php echo $userid['city'];?></td>
		</tr>
		<?php } ?>
		
		
		<?php if ( $userid['phone'] != "" )
			{ ?>
		<tr>
			<td style="width:9%;vertical-align:top; text-align:right;"></td>
			<td style='text-align:right;'>Telephone:</td>
			<td><?php echo $userid['phone'];?></td>
		</tr>
		<?php } ?>
		
		<?php if ( $userid['url_2'] != "" )
			{ ?>
		<tr>
			<td> </td>
		</tr>
		<tr>
			<td style="width:9%;vertical-align:top; text-align:right;"></td>	
			<td style='text-align:right;'>Website:</td>
			<td><?php echo $userid['url_2'];?></td>
		</tr>
		<?php } ?>
		<?php if ( $userid['skype'] )
			{ ?>
		<tr>
			<td style="width:9%;vertical-align:top; text-align:right;"></td>
			<td style='text-align:right;'>Skype:</td>
			<td><?php echo $userid['skype'];?></td>
		</tr>
		<?php } ?>
		<?php if ( $userid['pseudo_flickr'] != "" )
			{ ?>
		<tr>
			<td style="width:9%;vertical-align:top; text-align:right;"></td>
			<td style='text-align:right;'>Flickr:</td>
			<td><?php echo $userid['pseudo_flickr'];?></td>
		</tr>
		<?php } ?>
		<?php if ( $userid['ziki_url'] != "" )
			{ ?>
		<tr>
			<td style="width:9%;vertical-align:top; text-align:right;"></td>
			<td style='text-align:right;'>Ziki:</td>
			<td><?php echo $userid['ziki_url'];?></td>
		</tr>
		<?php } ?>
		
	</table>
	<br />
	<table class="mod" style="font-weight: bold; width:100%;font-size:1.2em"><tr><td style="width:100%;">Resume</td></tr></table>
	<br />
	<?php 
		$resume = utf8_decode($userid['resume']);
		$resume = str_replace('</p>','<br/>',$resume);
		$resume = str_replace('<p>','',$resume);
		
		$resume = str_replace('<ul>','<table>',$resume);
		
		$tr = "<tr>
			<td style='width:8%;vertical-align:top; text-align:right;'> </td>
			<td style='width:75%;'>";
			
		$resume = str_replace('<li>',$tr,$resume);
		$resume = str_replace('</li>','</td></tr>',$resume);

		$resume = str_replace('</ul>','</table>',$resume);
		
		
		?>
		
		<table>
		    <tr>
				<td style="width:4%;vertical-align:top; text-align:right;">
   
				</td>
				<td style="width:80%;"><?php echo $resume; ?></td>
			</tr>
		</table>
		
	<br/>

	<br/>

	<table class="mod" style="font-weight: bold; width:100%;font-size:1.2em"><tr><td style="width:100%;">Education</td></tr></table>
	<br />
	<table style="width:90%;">
	
	<?php	
		$sql = "SELECT * FROM $table_educ 
				WHERE user_id='$userid[user_id]'";
		$result = mysql_query($sql,$db);
				
		while($job = mysql_fetch_array($result))
		{
	
	?>
	
		  <tr>
			<td style="width:20%;vertical-align:top; text-align:right;"><?php echo disDate($job['dtstart'],$int="-",$sep="/");?> - <?php echo disDate($job['dtend'],$int="-",$sep="/");?> </td>
			<td style="width:5%;"></td>
			<td style="width:75%;"><?php echo utf8_decode($job['summary']);?></td>
		  </tr>
	
	<?php
	
	}
	
	?>
	
	</table>

	<br/>
	
	
	
	<br/>
	
	<table class="mod" style="font-weight: bold; width:100%;font-size:1.2em"><tr><td style="width:100%;">Exp Pro</td></tr></table>
	<br />
	
	<table style="width:90%;">

	<?php	
		$sql = "SELECT * FROM $table_exppro 
				WHERE user_id='$userid[user_id]'";
		$result = mysql_query($sql,$db);

		while($exp = mysql_fetch_array($result))
		{

	?>

		  <tr>
			<td rowspan='2' style="width:20%;vertical-align:top; text-align:right;"><?php echo disDate($exp['dtstart'],$int="-",$sep="/");?> - <?php echo disDate($exp['dtend'],$int="-",$sep="/");?> </td>
			<td rowspan='2' style="width:5%;"></td>
			<td style="width:75%;"><strong><?php echo utf8_decode($exp['titre']);?> - <?php echo utf8_decode($exp['employeur']);?></strong><br /></td>
		  </tr>
		  <tr>
		      <td style="width:75%;"><?php echo utf8_decode($exp['summary']);?></td>
		  </tr>

	<?php

	}

	?>

	</table><br />
	<?php
	if ( isset($_GET['vuehtml']) )
	{
		echo "</div>";

	}?>
</page>
<?php
	$content = ob_get_clean();
	require_once(dirname(__FILE__).'/../html2pdf.class.php');
	$pdf = new HTML2PDF('P','A4','fr');
	$pdf->WriteHTML($content, isset($_GET['vuehtml']));
	$pdf->Output();
	}
	
	
	else{
		echo "Vous n'etes pas autorise a telecharger ce CV.";
		header("Location: ../../index.php");
	}

}
else{
		echo "Il y a eu une erreur, vous allez etre redirige.";
		header("Location: ../../index.php");
	}	

?>